package com.dycx.user.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.*;

/**
 * @author 套餐枚举值
 * @date 2023/2/23
 */
@Getter
@AllArgsConstructor
public enum SetMealEnum {
    ONE_MONTH(1, "1个月", 1, 3900, 7800, 2, ""),
    THREE_MONTH(2, "3个月", 3, 9900, 19800, 3, ""),
    ONE_YEAR(3, "1年", 12, 13900, 27800, 4, "限时特价 性价比高"),
    THREE_YEAR(4, "3年", 36, 29900, 59800, 5, ""),
    PERPETUAL(5, "永久", -1, 39900, 89800, 6, "无限下载 赠送代理");

    private final Integer code;
    private final String name;
    private final Integer month;
    private final Integer money;
    private final Integer originMoney;
    private final Integer vip;
    private final String ad;


    public static String converter(Integer code) {
        return Arrays.stream(values()).filter(en -> en.code.equals(code)).findAny().orElse(ONE_MONTH).getName();
    }

    /**
     * 转为数据
     *
     * @return 枚举对象数组
     */
    public static List<Map<String, Object>> getList() {
        List<Map<String, Object>> list = new ArrayList<>();
        for (SetMealEnum item : SetMealEnum.values()) {
            Map<String, Object> map = new HashMap<>();
            map.put("code", item.getCode());
            map.put("name", item.getName());
            map.put("month", item.getMonth());
            map.put("money", item.getMoney());
            map.put("originMoney", item.getOriginMoney());
            map.put("vip", item.getVip());
            map.put("ad", item.getAd());
            list.add(map);
        }
        return list;
    }

    public static SetMealEnum getItem(Integer code) {
        for (SetMealEnum item : SetMealEnum.values()) {
            if (item.code.equals(code)) {
                return item;
            }
        }

        return null;
    }
}
